package com.janal.service.register;

import com.janal.model.user.User;
import com.janal.model.user.UserDao;
import com.janal.model.user.UserDaoImpl;
import com.janal.util.JdbcUtils;

import java.sql.Connection;
import java.sql.SQLException;

public class RegisterServiceImpl implements RegisterService{
    private UserDao userDao;

    public RegisterServiceImpl() {
        userDao = new UserDaoImpl();
    }

    @Override
    public boolean register(User user) {
        Connection conn = null;
        boolean flag = false;
        try {
            conn = JdbcUtils.getConnection();
            flag = userDao.setRegisterUser(conn,user);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            JdbcUtils.close(null,conn);
        }
        return flag;
    }
}
